home *** CD-ROM | disk | FTP | other *** search
/ Champak 29 / Volume 29 - JOGO DISK .iso / Games / jungle_adventure.swf / scripts / __Packages / GameVehicle.as < prev    next >
Text File  |  2006-11-29  |  6KB  |  181 lines

  1. class GameVehicle extends GameCharacter
  2. {
  3.    var classID = SSGlobal.CLSID_VEHICLE;
  4.    var assetID = "ATV";
  5.    var canTake = true;
  6.    var maxWalkForce = 2400;
  7.    var animationLabels = ["static","idle"];
  8.    var canCarry = false;
  9.    var canClimb = false;
  10.    var canSwing = false;
  11.    var canLockDisplayState = false;
  12.    var fuel = 1;
  13.    var fuelBurnRate = 0.06666;
  14.    var skidTime = 0;
  15.    var oldDX = 0;
  16.    var editor_isItem = true;
  17.    var editor_name = "ATV";
  18.    function GameVehicle()
  19.    {
  20.       super();
  21.    }
  22.    function onCollision(obj)
  23.    {
  24.       if(this.canTake && obj.classID == SSGlobal.CLSID_MAINCHAR)
  25.       {
  26.          if(obj.jumpTime)
  27.          {
  28.             return undefined;
  29.          }
  30.          this.owner = obj;
  31.          obj.controller.setControl(this);
  32.          this.velocity.x = obj.velocity.x * 0.5;
  33.          this.velocity.y = obj.velocity.y * 0.5;
  34.       }
  35.    }
  36.    function shiftFuel(v)
  37.    {
  38.       this.controller.fuel = this.fuel = Math.min(1,this.fuel + v);
  39.    }
  40.    function onAddToWorld()
  41.    {
  42.       this.originX = this.x;
  43.       this.originY = this.y;
  44.    }
  45.    function activate()
  46.    {
  47.       this.canTake = false;
  48.       GameSound.playSound("happy");
  49.       this.x = this.originX;
  50.       this.y = this.originY;
  51.       this.fuel = 1;
  52.       this.velocity.y = -1;
  53.       this.velocity.x = 0;
  54.       var _loc3_ = undefined;
  55.       var _loc2_ = _loc3_ = this.world.collections.fuel.length;
  56.       while((_loc2_ = _loc2_ - 1) > -1)
  57.       {
  58.          _loc3_[_loc2_].setActive(true);
  59.       }
  60.       this.snd = new Sound(this.target);
  61.       this.snd.attachSound("ATVIdle");
  62.       this.snd.start(0,1048575);
  63.       this.keepInScene = true;
  64.       this.shield = this.owner.shield;
  65.       this.owner.onShieldEnd();
  66.       this.immune = this.immuneAtStart;
  67.       this.setAnimationState(1);
  68.       this.world.viewport.setWatch(this);
  69.       this.controller.fuel = this.fuel;
  70.       this.health = this.controller.health;
  71.    }
  72.    function deactivate()
  73.    {
  74.       this.setAnimationState(0);
  75.       this.owner.moveTo(this.x,this.y,0);
  76.       this.target._visible = true;
  77.       this.target._rotation = 0;
  78.       this.owner.shield = this.shield;
  79.       this.onShieldEnd();
  80.       this.snd.stop();
  81.       this.snd = null;
  82.       this.owner.velocity.x = this.velocity.x * 0.5;
  83.       this.owner.velocity.y = this.velocity.y * 0.5 - 300;
  84.       this.keepInScene = false;
  85.       var _loc3_ = undefined;
  86.       var _loc2_ = _loc3_ = this.world.collections.fuel.length;
  87.       while((_loc2_ = _loc2_ - 1) > -1)
  88.       {
  89.          _loc3_[_loc2_].setActive(false);
  90.       }
  91.       var _loc4_ = new SSParticle(this.assetID,4,new Vector(this.velocity.x * 0.75,this.velocity.y * 0.75,-160),this.velocity.x >= 0 ? 45 : -45,600);
  92.       _loc4_.alpha = false;
  93.       _loc4_.x = this.x;
  94.       _loc4_.y = this.y;
  95.       this.world.addObject(_loc4_);
  96.       _loc4_.target.a._xscale *= this.velocity.x >= 0 ? 1 : -1;
  97.       this.moveTo(this.originX,this.originY,0);
  98.       this.canTake = true;
  99.    }
  100.    function onUpdate(elapsed)
  101.    {
  102.       this.fuel = this.controller.fuel = Math.max(Math.min(this.fuel - elapsed * this.fuelBurnRate,1),0);
  103.       if(!this.fuel || this.controller.action)
  104.       {
  105.          this.controller.setControl(this.owner);
  106.       }
  107.    }
  108.    function hurt()
  109.    {
  110.    }
  111.    function updateDisplay(elapsed, vX, vY, kJump)
  112.    {
  113.       if(vX != this.oldDX)
  114.       {
  115.          this.oldDX = vX;
  116.          this.snd.stop();
  117.          this.snd.attachSound(!vX ? "ATVIdle" : "ATVRevved");
  118.          this.snd.start(0,1048575);
  119.       }
  120.       if(this.dispCanTurn && vX && vX != this.dispAxis)
  121.       {
  122.          this.directionX = this.dispTurn = vX;
  123.          if(this.jumpTime && this.skidTime + 0.5 < this.world.time)
  124.          {
  125.             this.skidTime = this.world.time;
  126.             GameSound.playSound("skid");
  127.          }
  128.       }
  129.       if(this.contactSurface && (this.contactSurface.props & 3) == 3)
  130.       {
  131.          this.target._rotation = Math.atan2(this.contactSurface.normal.x,- this.contactSurface.normal.y) / 3.141592653589793 * 180;
  132.       }
  133.       else
  134.       {
  135.          this.target._rotation += (Math.atan2(this.velocity.y,this.velocity.x * this.dispAxis) / 3.141592653589793 * 45 * this.dispAxis - this.target._rotation) * elapsed * 2;
  136.       }
  137.       var _loc4_ = this.velocity.__get__length() * elapsed * 2;
  138.       this.target.a.mc.frontRim._rotation = this.target.a.mc.rearRim._rotation += _loc4_;
  139.       if(this.dispStateChanged || this.dispTurn)
  140.       {
  141.          if(this.dispTurn)
  142.          {
  143.             if(this.dispTurn > 0)
  144.             {
  145.                if((this.dispAxis = Math.min(1,this.dispAxis += elapsed * 2 / this.dispTurnTime)) == 1)
  146.                {
  147.                   this.dispTurn = 0;
  148.                }
  149.             }
  150.             else if((this.dispAxis = Math.max(-1,this.dispAxis -= elapsed * 2 / this.dispTurnTime)) == -1)
  151.             {
  152.                this.dispTurn = 0;
  153.             }
  154.          }
  155.          this.dispFrame = this.dispTurnFrames + Math.round(this.dispAxis * this.dispTurnFrames) + 1;
  156.          this.target.a.gotoAndStop(this.dispFrame);
  157.       }
  158.       this.dispStateChanged = false;
  159.    }
  160.    function onAddDisplay()
  161.    {
  162.       this.initColor();
  163.       this.target.gotoAndStop(1);
  164.       this.buildAnimationData();
  165.    }
  166.    function setDead(obj)
  167.    {
  168.       this.owner.health = this.controller.health = 0.01;
  169.       this.controller.setControl(this.owner);
  170.       this.owner.velocity.x = this.velocity.x;
  171.       this.owner.velocity.y = this.velocity.y - 800;
  172.    }
  173.    function endLevel(obj)
  174.    {
  175.       this.controller.setControl(this.owner);
  176.       this.owner.velocity.x = this.velocity.x * 0.5;
  177.       this.owner.velocity.y = this.velocity.y * 0.5;
  178.       this.owner.endLevel(obj);
  179.    }
  180. }
  181.